package splash;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JWindow;

public class Splash extends JWindow {

	public Splash(int delay) {
		JPanel p = new JPanel();
		p.setLayout(new BorderLayout());
		p.add(new SplashPicture("img/monopo.png"));
		p.setBorder(BorderFactory.createLineBorder(Color.BLUE, 1));
		getContentPane().add(p);
		setSize(900, 500);
		setLocationRelativeTo(null);
		setVisible(true);
		try {
			Thread.sleep(delay);
		}
		catch (Exception e) {}
	}

	public void dispose(int delay) {
		dispose();
		Splash s = new Splash(delay);
		s.dispose();
	}

	class SplashPicture extends JPanel {
		Image img;      

		public SplashPicture(String file) {
			img = new ImageIcon(file).getImage();
			repaint(); 
		}


		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			if (img == null)return;
			int w = img.getWidth(this);  
			int h = img.getHeight(this);
			boolean zoom = (w > getWidth() || h > getHeight());
			if (zoom) {
				g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
				
			}
			else g.drawImage(img, (getWidth()-w)/2, (getHeight()-h)/2, this);
		}
	}

}

